/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import da.ManagerJpaController;
import entities.Manager;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;

/**
 *
 * @author QUY_THI
 */
@Stateless
public class AdminLogin implements AdminLoginLocal {

    public boolean adminLogin(String username, String password) {
        boolean check = false;
        String pass = EncryptMD5.getHashString(password);
        EntityManager em = Persistence.createEntityManagerFactory("eBanking-ejbPU").createEntityManager();
        String sql = "select m from Manager m where m.username=:user and m.password=:pass";
        TypedQuery<Manager> query = em.createQuery(sql, Manager.class);
        query.setParameter("user", username);
        query.setParameter("pass", pass);
        List<Manager> resultList = query.getResultList();
        if (!resultList.isEmpty()) {
            check = true;
        }
        return check;
    }
}
